package com.example.travelhelper.controller;

import com.example.travelhelper.pojo.CustomerService;
import com.example.travelhelper.service.CustomerSeService;
import com.example.travelhelper.utils.ResponseData;
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import javax.ws.rs.GET;
import java.util.List;

/**
 * @Author: zq
 * @Description: TODO
 * @Date: 2024/4/9 11:53
 * @Version: 1.8
 */
@RestController
@RequestMapping("/admin/customerservice")
@CrossOrigin
public class CustomerSeController {
    @Autowired
    private CustomerSeService customerSeService;

    //增加客服账号
    @PostMapping
    public ResponseData addCustomerSe(@RequestParam("csUsername") String csUsername,@RequestParam("csTelephone") String csTelephone){
        if (customerSeService.selectByPhone(csTelephone)){
            return ResponseData.fail("电话已存在！");
        }
        customerSeService.addCustomerSe(csUsername,csTelephone);
        return ResponseData.success("添加成功");
    }

    @GetMapping("/isstate")
    public ResponseData isState(@RequestParam("csTelephone") String csTelephone){

            return customerSeService.isstate(csTelephone);
    }
/*    //删除客服账号
    @DeleteMapping("/{id}")
    public ResponseData deleteById(@PathVariable String id){
        customerSeService.deleteById(id);
        return ResponseData.success("删除成功！");
    }*/

    //删除客服账号m
    @DeleteMapping("/{id}")
    public ResponseData deleteById(@PathVariable String id){

        return customerSeService.deleteById(id);
    }

    //查询客服账号
    @GetMapping("/{id}")
    public ResponseData getById(@PathVariable String id){
        CustomerService customerService = customerSeService.getById(id);
        return ResponseData.success("查询成功",customerService);
    }

    //查询所有客服账号
    @GetMapping
    public ResponseData getAll(){
        List<CustomerService> customerServiceList = customerSeService.list();
        return ResponseData.success("查询所有数据",customerServiceList);
    }

/*    //修改客服账号
    @PutMapping
    public ResponseData update(@RequestBody CustomerService customerService){
        customerSeService.update(customerService);
        return ResponseData.success("更新成功！");
    }*/

    //修改客服账号
    @PutMapping
    public ResponseData update(@RequestBody CustomerService customerService){

        return customerSeService.update(customerService);
    }
    @PutMapping("/change")
    public ResponseData change(@RequestBody CustomerService customerService){
        return    customerSeService.updateState(customerService);

    }

    //获得一个客服电话
    @GetMapping("/getOne")
    public ResponseData getOne(){
        ResponseData responseData = customerSeService.getbyState();
        return responseData;
    }
}
